﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using BluePortal.Medias.Core;
using BluePortal.Framework;

namespace BluePortal.QuikStart.UserControls
{
    public partial class MediaProperties : System.Web.UI.UserControl
    {
        public Guid VideoId;
        public int FormatId = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //List video Format
                //@todo
                //IEnumerable<global::BluePortal.Core.BusinessObjects.OtherVideoAttach> lo = VideoAdapter.instance.FindByIDWithOtherVideoAttachs(VideoId).OtherVideoAttaches;
                //rblVideoFormat.Items.Add(new ListItem("Standard", "0"));
                //rblVideoFormat.SelectedIndex = 0;
                //foreach (global::BluePortal.Core.BusinessObjects.OtherVideoAttach o in lo)
                //{
                //    if (o.FormatId == 1)
                //        rblVideoFormat.Items.Add(new ListItem("HD", "1"));
                //    if (o.FormatId == 2)
                //        rblVideoFormat.Items.Add(new ListItem("Zune", "2"));
                //}

                BCMedia bc = new BCMedia();
                List<Media> v = new List<Media>();                
                v.Add(bc.FindByID(VideoId));
                //if (FormatId != 0)
                //{
                //    global::BluePortal.Core.BusinessObjects.OtherVideoAttach o = VideoAdapter.instance.FindByIDWithOtherVideoAttachs(VideoId).OtherVideoAttaches.Single(ova => ova.FormatId == FormatId);
                //    v.First().FileSize = o.FileSize;
                //    v.First().Width = o.Width;
                //    v.First().Height = o.Height;
                //    rblVideoFormat.SelectedIndex = FormatId;
                //}
                FormView1.DataSource = v;
                FormView1.DataBind();

            }
        }

        public int CountVideoComments()
        {
            return new BCComment().FindByMedia(VideoId, new FindParameters() { GetTotalCount = true}).TotalCount.Value;
        }

        protected void rblVideoFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            string url = Request.Url.AbsolutePath + "?vid=" + VideoId.ToString() + "&formatid=" + rblVideoFormat.SelectedValue;
            Response.Redirect(url, false);
        }


    }
}